home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / monoscr.com / MONO.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-03-30  |  8.1 KB  |  439 lines

  1. page    77, 132
  2. title    MONO.ASM - monochrome screen driver - 03/06/88
  3.  
  4. comment @
  5.         Written by Rick Richard, CompuServ ID#72560,2702
  6.         
  7. IMPROVEMENTS NEEDED:
  8.     1) BEEP function
  9.     2) positioning of cursor after print
  10.     3) destructive backspace
  11.     4) detect for mono on load, don't load if not present
  12. comment @
  13.  
  14.     cseg    segment    para public    'code'
  15. mono    proc    far
  16.         assume    cs:cseg, es:cseg, ds:cseg
  17.         org    0            ;
  18.  
  19. reqhdr        struc    ;fixed request header structure
  20. reqhdr_len        db    ?    ; len of packet
  21. reqhdr_unit        db    ?    ; unit code, block devices only
  22. reqhdr_cmd        db    ?    ; device driver comand
  23. reqhdr_status            dw    ?    ; returned by device driver
  24. reqhdr_res1        dd    ?    ; reserved
  25. reqhdr_res2        dd    ?    ; reserved
  26. reqhdr        ends
  27.  
  28. reqhdr0        struc    ;request header for Initialization (command 0)
  29. reqhdr0_fixed        db    size reqhdr dup(?)    ; fixed request header portion
  30. reqhdr0_nunits            db    ?        ; number of units
  31. reqhdr0_brk_ofs            dw    ?        ; offset address for break
  32. reqhdr0_brk_seg            dw    ?        ; segment address for break
  33. reqhdr0_bpb_tbo            dw    ?        ; offset address of pointer to BPB array
  34. reqhdr0_bpb_tbs            dw    ?        ; segment address of pointer to BPB array
  35. reqhdr0_drv_ltr            db    ?        ; first available drive (DOS 3+) block only
  36. reqhdr0        ends
  37.  
  38. reqhdr8        struc    ;request header for output (command 8)
  39. reqhdr8_fixed            db    size reqhdr dup(?)    ; fixed request header portion
  40. reqhdr8_media            db    ?        ; media descriptor from DPB
  41. reqhdr8_buf_ofs            dw    ?        ; offset address of data transfer area
  42. reqhdr8_buf_seg            dw    ?        ; segment address of data transfer area
  43. reqhdr8_count            dw    ?        ; transfer count in bytes
  44. reqhdr8_start            dw    ?        ; start sector number (block only)
  45. reqhdr8        ends
  46.  
  47. ;;;; MAIN ;;;;
  48.  
  49. begin:
  50.  
  51. ;;;; DEVICE HEADER ;;;;
  52.  
  53. next_dev    dd    -1        ; no other drivers
  54. attribute    dw    8000h        ; character, output, input
  55. strategy    dw    dev_strategy    ; strategy routine address
  56. interrupt    dw    dev_interrupt    ; interrupt routine address
  57. dev_name        db    'MONOSCR '    ; name of device driver
  58.                 db    '$'
  59. ;;;; WORK SPACE ;;;;
  60.  
  61. cursor_row    db    0
  62. cursor_col    db    0
  63. scr_cols    dw    80
  64. reqhdr_ofs    dw    ?        ; offset address of the request header
  65. reqhdr_seg    dw    ?        ; segment address of the request header
  66.  
  67. ;;;; STRATEGY PROCEDURE ;;;
  68.  
  69. dev_strategy:
  70.     mov    cs:reqhdr_seg, es        ; save the segment address
  71.     mov    cs:reqhdr_ofs, bx        ; save the offset address
  72.     ret                ; return to DOS
  73.  
  74. ;;;; INTERRUPT PROCEDURE ;;;;
  75.  
  76. dev_interrupt:
  77.     cld
  78.     push    ds
  79.     push    es
  80.     push    ax
  81.     push    bx
  82.     push    cx
  83.     push    dx
  84.     push    di
  85.     push    si
  86.  
  87.     mov    ax, cs:reqhdr_seg        ; restore ES as saved by strategy procedure
  88.     mov    es, ax
  89.     mov    bx, cs:reqhdr_ofs        ; restore BX as saved by strategy procedure
  90.  
  91. ;;; JUMP TO ROUTINE TO PROCESS COMMAND ;;;
  92.  
  93.     mov    al, es:[bx].reqhdr_cmd
  94.     rol    al, 1
  95.     lea    di, cmdtab
  96.     mov    ah, 0
  97.     add    di, ax
  98.     jmp    word ptr[di]
  99.  
  100. CMDTAB    label    byte
  101.     dw    INITIALIZATION
  102.     dw    NOT_SUPPORTED
  103.     dw    NOT_SUPPORTED
  104.     dw    NOT_SUPPORTED
  105.     dw    NOT_SUPPORTED
  106.     dw    NOT_SUPPORTED
  107.     dw    NOT_SUPPORTED
  108.     dw    NOT_SUPPORTED
  109.     dw    OUTPUT
  110.     dw    NOT_SUPPORTED
  111.     dw    NOT_SUPPORTED
  112.     dw    NOT_SUPPORTED
  113.     dw    NOT_SUPPORTED
  114.     dw    NOT_SUPPORTED
  115.     dw    NOT_SUPPORTED
  116.     dw    NOT_SUPPORTED
  117.     dw    NOT_SUPPORTED
  118.  
  119. ;;;; LOCAL PROCEDURES ;;;;
  120.  
  121. beep    proc    near
  122.     ret
  123. beep    endp
  124.  
  125.  
  126. position    proc    near
  127.     push    bx
  128.     mov    bx, ax
  129.     mov    al, ah
  130.     mul    byte ptr cs:scr_cols
  131.     xor    bh, bh
  132.     add    ax, bx
  133.     sal    ax, 1
  134.     pop    bx
  135.     ret
  136. position    endp
  137.  
  138. scroll_up    proc    near
  139.     push    ax
  140.     push    bx
  141.     push    cx
  142.     push    dx
  143.     push    si
  144.     push    di
  145.     push    bp
  146.     push    ds
  147.  
  148.     mov    ah, 7
  149.     mov    al, 1
  150.     mov    bx, 0701h
  151.     mov    cx, 0
  152.     mov    dh, 24
  153.     mov    dl, 79
  154.     
  155. n1:
  156.     push    bx
  157.     mov    ax, cx
  158.     call    scroll_position
  159.     jz    n7
  160.     add    si, ax
  161.     mov    ah, dh
  162.     sub    ah, bl
  163. n2:
  164.     call    n10
  165.     add    si, bp
  166.     add    di, bp
  167.     dec    ah
  168.     jnz    n2
  169. n3:
  170.     pop    ax
  171.     mov    al, ' '
  172. n4:
  173.     call    n11
  174.     add    di, bp
  175.     dec    bl
  176.     jnz    n4
  177. n5:
  178. n6:
  179.     pop    ds
  180.     pop    bp
  181.     pop    di
  182.     pop    si
  183.     pop    dx
  184.     pop    cx
  185.     pop    bx
  186.     pop    ax
  187.     ret
  188. n7:
  189.     mov    bl, dh
  190.     jmp    n3
  191.     ret
  192. scroll_up    endp
  193.  
  194.  
  195.  
  196. scroll_position    proc    near
  197. n9:
  198.     call    position
  199.     mov    di, ax
  200.     mov    si, ax
  201.     sub    dx, cx
  202.     inc    dh
  203.     inc    dl
  204.     xor    ch, ch
  205.     mov    bp, cs:scr_cols
  206.     add    bp, bp
  207.     mov    al, bl
  208.     mul    byte ptr cs:scr_cols
  209.     add    ax, ax
  210.     push    es
  211.     pop    ds
  212.     cmp    bl, 0
  213.     ret
  214. scroll_position    endp
  215.  
  216.  
  217. n10    proc    near
  218.     mov    cl, dl
  219.     push    si
  220.     push    di
  221.     rep    movsw
  222.     pop    di
  223.     pop    si
  224.     ret
  225. n10    endp
  226.  
  227. n11    proc    near
  228.     mov    cl, dl
  229.     push    di
  230.     rep    stosw
  231.     pop    di
  232.     ret
  233. n11    endp
  234.  
  235.  
  236. write_char    proc    near
  237.     push    ax
  238.     push    bx
  239.     push    cx
  240.     push    dx
  241.  
  242.     mov    dh, cs:cursor_row    ; y
  243.     mov    dl, cs:cursor_col    ; x
  244.  
  245. ;---- DX NOW HAS THE CURRENT CURSOR POSITION
  246.  
  247.     cmp    al, 08h        ; is it a BACKSPACE
  248.     je    u8        ; BACKSPACE
  249.     cmp    al, 0dh        ; is it a CARRIAGE RETURN
  250.     je    u9        ; CAR_RET
  251.     cmp    al, 0ah        ; is it a LINE FEED
  252.     je    u10        ; LINE_FEED
  253.     cmp    al, 07h        ; is it a BELL
  254.     je    u11        ; BELL
  255.     cmp    al, 0ch        ; is it a FORM FEED
  256.     je    u12        ; FORM_FEED
  257.     cmp    al, 09h        ; is it a TAB
  258.     je    u13        ; TAB
  259.  
  260.  
  261. ;---- WRITE THE CHAR TO THE SCREEN
  262.  
  263.     push    ax        ; save character
  264.     mov    ax, dx        ; row/col
  265.     call    position    ; calculate screen position
  266.     mov    di, ax
  267.     pop    ax        ; retrieve character
  268.     mov    ah, 7        ; set attribute
  269.     stosw            ; write the character
  270.  
  271. ;--- POSITION THE CURSOR FOR NEXT CHAR
  272.  
  273. repos:    inc    dl        ; increment column
  274.     cmp    dl, 80        ; test for column overflow
  275.     jl    exit        ; SET_CURSOR
  276.     mov    dl, 0        ; column for cursor
  277.     cmp    dh, 24
  278.     jl    set_c_exit    ; SET_CURSOR_INC
  279.  
  280. ;---- SCROLL REQUIRED
  281.  
  282.     call    scroll_up
  283.     jmp    SHORT exit
  284.  
  285. set_c_exit:
  286.     
  287.     inc    dh
  288.     jmp    SHORT exit
  289.  
  290. ;---- BACK SPACE FOUND
  291.  
  292. u8:
  293.     cmp    dl, 0        ; already at end of line
  294.     je    exit        ; set_cursor
  295.     dec    dl        ; no, just move it back
  296.     jmp    SHORT exit    ; set_cursor
  297.  
  298. ;---- CARRIAGE RETURN FOUND
  299.  
  300. u9:
  301.     mov    dl, 0        ; move to first column
  302.     jmp    SHORT exit    ; set_cursor
  303.  
  304. ;---- LINE FEED FOUND
  305.  
  306. u10:
  307.     cmp    dh, 24        ; bottom of screen
  308.     jne    set_c_exit    ; yes, scroll the screen
  309.     call    scroll_up
  310.     jmp    SHORT exit
  311.  
  312. ;---- BELL FOUND
  313.  
  314. u11:
  315.     call    beep        ; sound the bell
  316.     jmp    SHORT exit    ; write_char return
  317.  
  318. ;----FORM FEED FOUND
  319.  
  320. u12:
  321.     mov    dx, 0        ; reset the cursor position
  322.     mov    cx, 2000    ; repeat count
  323.     mov    ax, 0700h    ; attribute and color
  324.     mov    di, 0        ; starting screen position
  325.     rep    stosw
  326.     jmp    SHORT exit
  327.  
  328. ;----TAB CHARACTER FOUND
  329. u13:
  330.     mov    ax, dx        ; row/col
  331.     call    position    ; calculate screen position
  332.     mov    di, ax
  333.     mov    ax, 720h    ; set character and attribute
  334. nxttab:    stosw            ; write the character
  335.     inc    dl        ; increment column
  336.     test    dl, 07h        ; test for ?????111
  337.     jnz    nxttab        ; when not all zeros - continue
  338.     dec    dl
  339.     jmp    repos        ; go for next character
  340.  
  341. exit:
  342.     mov    cs:cursor_row, dh
  343.     mov    cs:cursor_col, dl
  344.     pop    dx
  345.     pop    cx
  346.     pop    bx
  347.     pop    ax
  348.     ret            ; return to caller
  349.  
  350. write_char    endp
  351.  
  352. ;;;; DOS COMMAND PROCESSING ;;;;
  353.  
  354. Initialization:        ; command 0
  355.     call    initial
  356.     lea    ax, initial
  357.     mov    es:[bx].reqhdr0_brk_ofs, ax     ; Ending offset for this device driver
  358.     mov    es:[bx].reqhdr0_brk_seg, cs     ; Ending segment for this device driver
  359.     jmp    SHORT done
  360.  
  361.  
  362. Output:                  ; command 8
  363.     push    ds
  364.     mov    cx, es:[bx].reqhdr8_count
  365.     mov    si, es:[bx].reqhdr8_buf_ofs
  366.     mov    ax, es:[bx].reqhdr8_buf_seg
  367.     mov    ds, ax
  368.     mov    bx, 0
  369.     mov    ax, 0b000h        ; monochrome screen
  370.     mov    es, ax
  371.     cld
  372. out1:
  373.     mov    al, ds:[si]
  374.     inc    si
  375.     call    write_char
  376.     loop    out1
  377.  
  378.     mov    ax, cs:reqhdr_seg
  379.     mov    es, ax
  380.     mov    bx, cs:reqhdr_ofs
  381.     pop    ds
  382.     jmp    SHORT done
  383.  
  384. ;;;;;;;;;;;;;;;;;;;;;; UNUSED DEVICE FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  385.  
  386. NOT_SUPPORTED:
  387.     jmp    SHORT done
  388.  
  389. unknown:
  390.     or    es:[bx].reqhdr_status, 8003h
  391.     jmp    SHORT done1
  392.  
  393. busy:
  394.     or    es:[bx].reqhdr_status, 0200h
  395.     jmp    SHORT done1
  396.  
  397. done:
  398.     or    es:[bx].reqhdr_status, 0100h
  399.  
  400. done1:
  401.     pop    si
  402.     pop    di
  403.     pop    dx
  404.     pop    cx
  405.     pop    bx
  406.     pop    ax
  407.     pop    es
  408.     pop    ds
  409.     ret
  410.  
  411.  
  412. initial    proc    near
  413.     push    ax
  414.     push    dx
  415.  
  416. ;;; PRINT SIGN-ON BANNER ;;;
  417.     lea    dx, BANNER
  418.     mov    ah, 9
  419.     int    21h
  420.     cld
  421.  
  422.     pop    dx
  423.     pop    ax
  424.  
  425.     ret
  426. initial    endp
  427.  
  428. BANNER    db    0AH, 0DH, '┌───────────────────────────────────────┐'
  429.     db    0AH, 0DH, '│ Monochrome Screen Driver V1.0         │'
  430.     db    0AH, 0DH, '│ Device Name: MONOSCR                  │'
  431.     db    0AH, 0DH, '│ Written By : Rick Richard, 3/6/88     │'
  432.     db    0AH, 0DH, '└───────────────────────────────────────┘'
  433.     db    0AH, 0DH, '$'
  434. BANNER_SIZE    EQU $-BANNER    
  435.  
  436. mono    endp
  437. cseg    ends
  438.     end    begin
  439.